home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.graphics.algorithms,rec.games.programmer
- Path: mxsld2.pd.infn.it!LORETI
- From: loreti@mxsld2.pd.infn.it (Maurizio Loreti)
- Subject: Re: Speed question here...
- X-Nntp-Posting-Host: mxsld2.pd.infn.it
- Message-ID: <Dn2nAL.Jn4@news.cern.ch>
- Sender: news@news.cern.ch (USENET News System)
- Reply-To: loreti@mxsld2.pd.infn.it
- Organization: I.N.F.N. Padova - CDF/CMS VAXcluster
- References: <4ftluh$1gkv@hearst.cac.psu.edu>,<4gc5ce$rtv@news.eunet.ch>
- Date: Tue, 20 Feb 1996 11:15:55 GMT
-
- In article <4gc5ce$rtv@news.eunet.ch>, Reto Koradi <kor@spectrospin.ch> writes:
- >koscho@wjk130.rh.psu.edu (William Koscho) wrote:
- >>I was curious as to how fast something like the
- >>following would execute:
- >>
- >> int x;
- >> node *ptr; ptr in linked list
- >>
- >> for ( ptr = first_node; ptr != NULL; ptr = ptr.next ) {
- >> for ( x = 0; x < max; x++ ) {
- >> array[x] = array_other[x];
- >> }
- >> }
- >
- >You could take the inner loop outside of the outer loop, it doesn't depend
- >on ptr. A good compiler might do that automatically, but it certainly
- >couldn't hurt. So replace it by:
- >
- > for ( x = 0; x < max; x++ ) {
- > array[x] = array_other[x];
- > }
- > for ( ptr = first_node; ptr != NULL; ptr = ptr.next ) {
- > }
-
- Then optimize the last loop to ptr = NULL; you see, traversing the
- tree costs nothing at all.
- 8^)
- --
- Maurizio Loreti http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
- Un. of Padova, Dept. of Physics - Padova, Italy loreti@padova.infn.it
-